# -*- coding:UTF-8 -*-
"""
@Project : pythonProject
@File    : AccountloginSimulation.py
@IDE     : PyCharm
@Author  : WorldWind(1772830365@qq.com)
@Address : China - HeiLongjiang - Herbin
@Date    : 2025/7/7 下午8:55
"""
# 参照如下用户信息，编写代码，模拟某系统用户采用用户名和密码登陆的方式，合法用户和密码见userAccount表；要求按照流程图实现相关业务逻辑
userAccount = {
    '1001': {'name': 'Kate', 'password': '111111'},
    '2009': {'name': 'Linda', 'password': '123456'},
    '3007': {'name': 'Mike', 'password': '222222'},
    '4219': {'name': 'Joyce', 'password': '333333'},
}


def checkUsername(username):
    for user in userAccount.values():
        if user['name'] == username:
            return True  # 数据库中含有此用户的用户名
    else:
        return False  # 数据库中未查到此人


def checkPassword(name, password):
    for user in userAccount.values():
        if user['name'] == name and user['password'] == password:
            return True
    else:
        return False

print("Welcome to visit!")
while 1:
    username = input("Please enter your username")
    if checkUsername(username):
        times = 0
        while 1:
            if times == 3:
                print("Please contact the administrator!")
                break
            password = input("Please enter your password")
            if checkPassword(username, password):
                print("Welcome " + username + "!")
                break
            else:
                print("Sorry " + username + "'s password is incorrect!")
                times += 1
        break
    else:
        print("Invalid Username!")